





//
//  NQIyeRecruitDetailVC.m
//  nncloud
//
//  Created by macfai on 2018/11/28.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NQIyeRecruitDetailVC.h"
#import "NZhaopinCell.h"
#import "NMiaoshuCell.h"
@interface NQIyeRecruitDetailVC ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArray;

@property(nonatomic,strong)NSArray *titleArray;

@property(nonatomic,strong)NSArray *infoArray;

///岗位介绍
@property (nonatomic,copy)NSString *jobInfo;
///公司介绍
@property (nonatomic,copy)NSString *companyInfo;


@end

@implementation NQIyeRecruitDetailVC

//招聘详情
#define cellIdentifier @"zhaopin"
#define miaoshuCell @"miaoshu"
#define SectionHeaderHeight  10.f
#define kAdjustValue  150.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
//        _tableView.rowHeight = 115.f;
        _tableView.separatorStyle = 0;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NZhaopinCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        [_tableView registerNib:[UINib nibWithNibName:@"NMiaoshuCell" bundle:nil] forCellReuseIdentifier:miaoshuCell];
        _tableView.showsVerticalScrollIndicator = NO;
        
    }
    return _tableView;
}


- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    
    self.dataArray = [NSMutableArray array];
    
    [self.navigationItem setItemWithTitle:@"职位信息" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    
    self.titleArray = @[@"行业",@"职业",@"招聘部门",@"招聘人数",@"工作地区",@"工作性质",@"性别要求",@"婚姻要求",@"学历要求",@"工作经验",@"年龄要求",@"待遇水平",@"更新日期",@"有效期至",];
//    self.infoArray = @[@"互联网",@"java",@"大数据事业部",@"3",@"北京",@"全职",@"男",@"无",@"本科",@"3年",@"35",@"面议",@"刚刚",@"2019-12-31",];
    
    [self.view addSubview:self.tableView];
    
    [self loadData];
    
}

- (void)loadData{
    
    NSDictionary *dic = @{@"empInfoId":self.zhaopinId};
    [SVProgressHUD show];
    [[NNRCNetRequest manager]getWithUrl:kZhaopinDetailUrl params:dic success:^(id result) {
        
        YYLog(@"%@",result);
        WeakStament(ws);
        if ([[result objectForKey:@"code"] integerValue] == 0) {
            NSDictionary *dict = result[@"page"];
            NQiuzhiModel *model = [NQiuzhiModel mj_objectWithKeyValues:[dict deleteNull]];
            [ws.dataArray addObject:model];
            [ws formDataWithModel:model];
            [ws.tableView reloadData];
            [SVProgressHUD dismiss];
            
        }else{
            [AFToast showText:result[@"msg"]];
        }
        
    } failure:^(id failure) {
        
    }];
}

- (void)formDataWithModel:(NQiuzhiModel *)model {
    
    NSString *male = model.empInfoIndustry;
    NSString *birth = model.empInfoPosition;
    NSString *marriage = model.empInfoDept;
    NSString *height = model.empInfoNum;
    NSString *weight = model.empInfoArea;
    NSString *area =  model.empInfoProperty;
    NSString *xueli = model.empInfoSex;
    NSString *school = model.empInfoMarriage;
    NSString *professtino = model.empInfoEducation;
    NSString *workXingzhi = model.empInfoExperience;//民营还是国企
    NSString *experince =  model.empInfoAge;
    NSString *hangyeyixiang = model.empinfoPrice;
    NSString *zhiweiyixiang  = [[ToolKit getTimeFromTimesTamp:model.empInfoUpdateTime]substringToIndex:10];
    NSString *jineng = [[ToolKit getTimeFromTimesTamp:model.empInfoIndateTime] substringToIndex:10];
//    NSString *salary = model.resumeSalary;
//    NSString *status = model.resumeJobStatus;
    
    self.infoArray = @[male,birth,marriage,height,weight,area,xueli,school,professtino,workXingzhi,experince,hangyeyixiang,zhiweiyixiang,jineng,];
}




- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    if (indexPath.section==0) {
        
        return 50.f;
        
    }else if (indexPath.section==1){
        return 45.f;
    }
    else if (indexPath.section==2){
        
//        return 150.f;
        if (self.jobInfo.length<10) {
            
            return 80.f;
            
        }else{
            
            ///调整值
//            CGFloat adjustValue = 100.f;
            //这个值在不同的屏幕上显示会有差别,尽量给的大一点，他包括内容label的上下的margin 或者理解成padding
            return  [self getCellHeight:self.jobInfo withWidth:ScreenWidth-20]+kAdjustValue;
            
        }

    }
    else if (indexPath.section==3){
//        return 150.f;
        if (self.companyInfo.length<10){
            return 80.f;
        }else{
//             CGFloat adjustValue = 100.f;
             return  [self getCellHeight:self.companyInfo withWidth:ScreenWidth-20]+kAdjustValue;
        }
       
    }
    return 0.f;
    
}
#pragma mark - datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0||section==2||section==3) {
        return 1;
    }else if (section==1){
        return self.infoArray.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NQiuzhiModel *model = [self.dataArray lastObject];
    
    if (indexPath.section==0) {
        
        NZhaopinCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        cell.area.hidden = YES;
        cell.date.hidden = YES;
        cell.company.hidden = YES;
        cell.salary.hidden = YES;
        cell.nameLeftMargin.constant = 25.f;
        cell.name.font = [UIFont boldSystemFontOfSize:15];
        cell.name.text = model.empInfoTitle;
        return cell;
        
    }else if(indexPath.section==1){
        
        NZhaopinCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        cell.nameLeftMargin.constant = 25.f;
        cell.area.hidden = YES;
        cell.date.hidden = YES;
        cell.company.hidden = YES;
        cell.salary.hidden = false;
        cell.name.text = self.titleArray[indexPath.row];
        cell.name.font = kFont15;
        cell.salary.text = self.infoArray[indexPath.row];
        return cell;
        
        
    }else if (indexPath.section==2){
        
        NMiaoshuCell *cell = [tableView dequeueReusableCellWithIdentifier:miaoshuCell forIndexPath:indexPath];
        cell.nameLabel.text = @"职位描述";
        if (model.empInfoDescribe.length<2) {
            cell.detailLable.text = @"暂无介绍";
            self.jobInfo = @"暂无介绍";
        }else{
            cell.detailLable.text = model.empInfoDescribe;
            self.jobInfo = model.empInfoDescribe;
        }
        return cell;
        
    }
    
    else if(indexPath.section==3){

        NMiaoshuCell *cell = [tableView dequeueReusableCellWithIdentifier:miaoshuCell forIndexPath:indexPath];
        cell.nameLabel.text = @"公司介绍";
        if (model.empInfoIntro.length<2) {
            cell.detailLable.text = @"暂无介绍";
            self.companyInfo = @"暂无介绍";
        }else{
            cell.detailLable.text = model.empInfoIntro;
            self.companyInfo = model.empInfoIntro;
        }
//        cell.backgroundColor = kMagentaColor;
        return cell;
    }

    return nil;
}


#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

#pragma mark - 动态行高
///直接返回行高 比返回size那个少了一个步骤  推荐使用这个方法
- (CGFloat)getCellHeight:(NSString *)str withWidth:(CGFloat)width{
    CGSize size = CGSizeMake(width,MAXFLOAT); //设置一个行高上限
    NSDictionary *attribute = @{NSFontAttributeName: kFont13};//给一个字体大小
    CGSize labelsize = [str boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine| NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    return ceil(labelsize.height);
}

//根据字符串内容返回字符串的size
- (CGSize)sizeWithLabelWithContent:(NSString *)content width:(CGFloat)width font:(UIFont *)font{
    
    NSDictionary *dict=@{NSFontAttributeName : font};
    CGRect rect=[content boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dict context:nil];
    CGFloat sizeWidth=ceilf(CGRectGetWidth(rect));
    CGFloat sizeHieght=ceilf(CGRectGetHeight(rect));
    return CGSizeMake(sizeWidth, sizeHieght);
}

@end
